package cn.neusoft.service.impl;

import cn.neusoft.po.RoleMenu;
import cn.neusoft.mapper.RoleMenuMapper;
import cn.neusoft.po.RolePermission;
import cn.neusoft.service.IRoleMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hxj
 * @since 2023-12-19
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements IRoleMenuService {

    @Transactional
    @Override
    public boolean changeRoleMenus(Integer roleId, List<RoleMenu> roleMenus) {
        //delete from t_role_menu where role_id=14
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_id",roleId);
        int delete = baseMapper.delete(queryWrapper);

        if (delete>0){
            //调用service层的批量添加
            return saveBatch(roleMenus);
        }
        return false;
    }

}
